package fr.imag.adele.cprobes.util;

import java.util.Date;
import java.util.Dictionary;
import java.util.Enumeration;
import java.util.Hashtable;

public class DataEvent {
	
	private Dictionary	m_data;
	public final static String CP_EVENT_RESOURCE 	= "cp.event.resource";
	public final static String CP_EVENT_SOURCE 		= "cp.event.source";
	public final static String CP_EVENT_TIMESTAMP 	= "cp.event.timestamp";
	public final static String CP_EVENT_VALUE 		= "cp.event.value";
	public final static String CP_EVENT_UNIT 		= "cp.event.unit";
	
	/**
	 * The DataEvent Constructor
	 * 
	 * @param resource  the resource that is captured
	 * @param source	the source of the event
	 * @param timeStamp	the time where the event happened
	 * @param value		the value of the captured resource
	 * @param unit		the unit used
	 * @param extraData	an extra data that was collected with the captured resource
	 */
	public DataEvent(String resource, String source, String timeStamp, 
			Object value, String unit, Dictionary extraData){
		
		m_data = new Hashtable();
		m_data.put(DataEvent.CP_EVENT_RESOURCE, resource);
		m_data.put(DataEvent.CP_EVENT_SOURCE, source);
		m_data.put(DataEvent.CP_EVENT_TIMESTAMP, new Date().toString());		
		m_data.put(DataEvent.CP_EVENT_VALUE, value);
		m_data.put(DataEvent.CP_EVENT_UNIT, unit);
		if (extraData != null){
			Enumeration e = extraData.keys();
			while (e.hasMoreElements()){
				String key = (String)e.nextElement();
				m_data.put(e, extraData.get(e));
			}
		}		
	}
	
	// Getters and setters	
	
	public String getResource(){
		return (String)this.m_data.get(DataEvent.CP_EVENT_RESOURCE);
	}
	
	public String getSource(){
		return (String)this.m_data.get(DataEvent.CP_EVENT_SOURCE);
	}
	
	public String getTimeStamp(){
		return (String)this.m_data.get(DataEvent.CP_EVENT_TIMESTAMP);
	}
	
	public Object getValue(){
		return this.m_data.get(DataEvent.CP_EVENT_VALUE);
	}
	
	public String getUnit(){
		return (String)this.m_data.get(DataEvent.CP_EVENT_UNIT);
	}
	
	public Dictionary getAllData(){
		return this.m_data;
	}
	
	public Object getDataInfo(Object key){		
		return m_data.get(key);
	}
	
	public void setResource(String resource){
		this.m_data.remove(DataEvent.CP_EVENT_RESOURCE);
		m_data.put(DataEvent.CP_EVENT_RESOURCE, resource);
	}
	
	public void setSource(String source){
		this.m_data.remove(DataEvent.CP_EVENT_SOURCE);
		m_data.put(DataEvent.CP_EVENT_SOURCE, source);
	}
	
	public void setTimeStamp(String timeStamp){
		this.m_data.remove(DataEvent.CP_EVENT_TIMESTAMP);
		m_data.put(DataEvent.CP_EVENT_TIMESTAMP, timeStamp);
	}	
	
	public void setValue(String value){
		this.m_data.remove(DataEvent.CP_EVENT_VALUE);
		m_data.put(DataEvent.CP_EVENT_VALUE, value);
	}
	
	public void setUnit(String unit){
		this.m_data.remove(DataEvent.CP_EVENT_UNIT);
		m_data.put(DataEvent.CP_EVENT_UNIT, unit);
	}
}
